package com.baidu.mobads.demo.main.feeds;
import java.util.Timer;
import java.util.TimerTask;

import com.meitu.wheecam1.R;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;


public class MainActivity extends Activity {
	private  int REQUEST_CODE = 1;
	private  int clickCount = 1;
	private  Button sampleFloatBannerBtn,sampleBannerBtn,sampleInterstitialBtn;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        Button btnListView = (Button) this.findViewById(R.id.btnList);
        btnListView.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View v) {
                // 开启信息流广告形式
                startActivity(new Intent(MainActivity.this, ListViewActivity.class));
            }

        });
        Button btnOrigin = (Button) this.findViewById(R.id.btnOrigin);
        btnOrigin.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View v) {
                // 开启原生字段形式
                startActivity(new Intent(MainActivity.this, NativeOriginActivity.class));
            }

        });
        Button btnReconfirm = (Button) this.findViewById(R.id.btnReconfirm);
        btnReconfirm.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View v) {
                // 开启非WiFi下二次确认下载activity
                startActivity(new Intent(MainActivity.this, ReconfirmActivity.class));
            }

        });
        Button btnVideoFeed = (Button) this.findViewById(R.id.btnVideoFeed);
        btnVideoFeed.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View v) {
                // 开启非WiFi下二次确认下载activity
                Intent intent = new Intent(MainActivity.this, VideoFeedActivity.class);
                startActivity(intent);
            }
            
        });
    }

    @Override
    public void onDestroy() {
        super.onDestroy();
    }

    @Override
    public void onResume() {
        super.onResume();
    }
    
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    	if(requestCode==REQUEST_CODE){
    		clickCount = resultCode;
    		if(++clickCount > 3){
    			clickCount = 1;
    		}
    		clickButton();
    	}
    }
    private void clickButton(){
    	timer = new Timer();
    	task = new TimerTask(){  
     	   
            public void run() {  
                Message message = new Message();      
                message.what = clickCount;     
                handler.sendMessage(message);
            }  
               
        }; 
    	timer.schedule(task, 1000,1000);
    }
    
    private Timer timer;

    Handler handler = new Handler(){  
    	   
        public void handleMessage(Message msg) {  
            switch (msg.what) { 
            case 1:
            	
            	timer.cancel();
            	task.cancel();
            	task = null;
            	timer = null;
            	sampleBannerBtn.performClick();
            	break;
            case 2:      
            	timer.cancel();
            	task.cancel();
            	task = null;
            	timer = null;
            	sampleFloatBannerBtn.performClick();
                break;      
            case 3:
            	sampleInterstitialBtn.performClick();
            	timer.cancel();
            	task.cancel();
            	task =null;
            	timer = null;
            	break;
            }      
            super.handleMessage(msg);  
        }  
    };
    
    TimerTask task;
}
